from sqlalchemy import Column, ForeignKey
from sqlalchemy.orm import declarative_base
from sqlalchemy.sql.sqltypes import Integer, VARCHAR, TIMESTAMP, DECIMAL
from sqlalchemy.sql.functions import now
Base = declarative_base()


class User(Base):
    __tablename__ = 't_user'

    usrId = Column(
        Integer,
        primary_key=True,
        autoincrement=True,
        nullable=False
    )
    name = Column(VARCHAR(20), nullable=False)
    rmk = Column(VARCHAR(100))
    ttlInc = Column(DECIMAL, nullable=False, default=0)
    ttlSpd = Column(DECIMAL, nullable=False, default=0)
    trascStatus = Column(VARCHAR(4), nullable=False, default='盈亏平衡')
    crtTm = Column(TIMESTAMP, nullable=False, default=now())
    updTm = Column(TIMESTAMP)


class Transaction(Base):
    __tablename__ = 't_transaction'

    trascFlowNum = Column(
        Integer,
        primary_key=True,
        autoincrement=True,
        nullable=False
    )
    trascType = Column(VARCHAR(2), nullable=False)
    money = Column(DECIMAL, nullable=False)
    event = Column(VARCHAR(100))
    trascUsrId = Column(Integer, ForeignKey('t_user.usrId'), nullable=False)
    trascTm = Column(TIMESTAMP, nullable=False, default=now())
